package com.mini.cn.goods.aop;

import com.mini.cn.goods.action.ActionProxy;
import com.mini.cn.goods.action.BaseAction;
import com.mini.cn.goods.config.BaseConfig;
import com.mini.cn.goods.dao.IUserDao;
import com.mini.cn.goods.po.UserInfo;
import com.mini.cn.goods.po.dto.OrderDto;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: fly
 * Date: 2022/11/19
 * Time: 18:42
 */
@Component  //加入到IoC容器
@Aspect  //指定当前类为切面类
@Slf4j
public class GroupOrderAop {

    @Autowired
    ActionProxy actionProxy;

    @Autowired
    IUserDao userDao;

    @Pointcut("execution(* com.mini.cn.goods.service.OrderService.groupOrder(..))")
    public void pointCut() {

    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        log.info("GroupSaleAop aroud come in");
        //访问目标方法的参数：
        Object[] args = point.getArgs();
        OrderDto orderDto = (OrderDto) args[0];
        String openId = orderDto.getOpenId();
        int appId = orderDto.getAppId();
        UserInfo userInfo = userDao.checkUserByOpenid(openId, appId);
        BaseAction action = actionProxy.createRealAction(BaseConfig.GROUPSALEACTION, userInfo, null);
        actionProxy.findActionGift(action);
        return point.proceed(args);
    }
}
